#include<iostream>
#include<string>
using namespace std;
string s = "314159265358979323846264338327";
string ans;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> ans;
		int ans1 = 0;
		for (int i = 0; i < ans.size(); i++) {
			if (ans[i] == s[i]) {
				ans1++;
			}
			else {
				break;
			}
		}
		cout << ans1 << endl;
	}
	return 0;
}